﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FileMonitor.Configuration.Prototype;
using FileMonitor.Configuration.Prototype.Provider;
using FileUtility;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace FileMonitor.Configuration.Providers
{
    public class PlantProcessConfigurationProvider:IPlantProcessConfiguration
    {
        public List<PlantProcessConfiguration> GetPlantProcessConfiguration(SqlDatabase db, string PlantCode, string DataType)
        {
            try
            {
                DataTable dt = FileUtility.DBUtility.ReadProcessConfigByPlant(db, PlantCode, DataType);
                List<PlantProcessConfiguration> list = new List<PlantProcessConfiguration>();
                foreach (DataRow dr in dt.Rows)
                {
                    string proType = dr["ProcessType"].ToString();
                    string ftpPath = dr["FTPPath"].ToString();
                    string ftpUserName = dr["FTPUserName"].ToString();
                    string ftpPassword = dr["FTPPassword"].ToString();
                    string ftpPort = dr["FTPPort"].ToString();
                    string ftpFolderPath = dr["FTPFolderPath"].ToString();
                    string DBConnString = dr["DBConnString"].ToString();

                    if (string.Compare("FTP", proType, true) == 0)
                    {
                        PlantProcessConfiguration plantConfig = new PlantProcessConfiguration(ProcessType.FTP, PlantCode, DataType, string.Empty, ftpPath, ftpUserName, ftpPassword, ftpFolderPath, ftpPort);
                        list.Add(plantConfig);
                    }
                    else if (string.Compare("EXCHANGEDB", proType, true) == 0)
                    {
                        PlantProcessConfiguration plantConfig = new PlantProcessConfiguration(ProcessType.ExChangeDB, PlantCode, DataType, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                        list.Add(plantConfig);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
